package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.ProxyIp;
import com.ruoyi.business.service.IProxyIpService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 代理管理Controller
 * 
 * @author leach
 * @date 2020-08-02
 */
@Controller
@RequestMapping("/business/ip_manage")
public class ProxyIpController extends BaseController
{
    private String prefix = "business/ip_manage";

    @Autowired
    private IProxyIpService proxyIpService;

    @RequiresPermissions("business:ip_manage:view")
    @GetMapping()
    public String ip_manage()
    {
        return prefix + "/ip_manage";
    }

    /**
     * 查询代理管理列表
     */
    @RequiresPermissions("business:ip_manage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProxyIp proxyIp)
    {
        startPage();
        List<ProxyIp> list = proxyIpService.selectProxyIpList(proxyIp);
        return getDataTable(list);
    }

    /**
     * 导出代理管理列表
     */
    @RequiresPermissions("business:ip_manage:export")
    @Log(title = "代理管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProxyIp proxyIp)
    {
        List<ProxyIp> list = proxyIpService.selectProxyIpList(proxyIp);
        ExcelUtil<ProxyIp> util = new ExcelUtil<ProxyIp>(ProxyIp.class);
        return util.exportExcel(list, "ip_manage");
    }

    /**
     * 新增代理管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存代理管理
     */
    @RequiresPermissions("business:ip_manage:add")
    @Log(title = "代理管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProxyIp proxyIp)
    {
        return toAjax(proxyIpService.insertProxyIp(proxyIp));
    }

    /**
     * 修改代理管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProxyIp proxyIp = proxyIpService.selectProxyIpById(id);
        mmap.put("proxyIp", proxyIp);
        return prefix + "/edit";
    }

    /**
     * 修改保存代理管理
     */
    @RequiresPermissions("business:ip_manage:edit")
    @Log(title = "代理管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProxyIp proxyIp)
    {
        return toAjax(proxyIpService.updateProxyIp(proxyIp));
    }

    /**
     * 删除代理管理
     */
    @RequiresPermissions("business:ip_manage:remove")
    @Log(title = "代理管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(proxyIpService.deleteProxyIpByIds(ids));
    }
}
